% array is in the following order:
% array = [X11 Y11 Z11 X21 Y21 Z21 .... X12 Y12 Z12 X22 Y22 Z22 ....];

function tensor = array2tensor(array),
% We assume a square grid
N=sqrt(length(array)/3);
tensor = zeros(N,N,3);
for i=1:N,
    for j=1:N,
        tensor(i,j,:)=array((i+N*(j-1))*3-2:(i+N*(j-1))*3,1);
    end
end

